package com.lhkj.ct.admin.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.admin.model.entity.TblLoginLog;
import com.lhkj.ct.meta.admin.service.LoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 登录日志 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-09-20
 */
@RestController
@RequestMapping("api/system/loginLog")
@ApiSupport(order = 13)
@Api(tags = {"13.登录日志"})
@Validated
public class LoginLogController {

    @Resource
    private LoginLogService loginLogService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "登录日志列表", notes = "分页查询")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public ActionResult<IPage<TblLoginLog>> list(TblLoginLog loginLog, PageQuery pageQuery) {
        return ActionResult.success(loginLogService.selectLoginLogPage(loginLog, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "删除日志")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", actionType = ActionType.DELETE)
    @DeleteMapping("/delete")
    public ActionResult remove(@Validated @NotEmpty(message = "日志id不能为空") @RequestBody List<String> ids) {
        return ActionResult.judge(loginLogService.removeByIds(ids));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "清空日志")
//    //@RequiresPermissions("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", actionType = ActionType.CLEAN)
    @DeleteMapping("/clean")
    public ActionResult<Void> clean() {
        loginLogService.clear();
        return ActionResult.success();
    }
}
